package net.hn.hnms.biz.gasext.dws.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import net.hn.hnms.biz.gasext.dws.domain.DwsAqjcYcbjDFPo;
import net.hn.hnms.biz.gasext.dws.domain.DwsRyDdwRyDFPo;
import net.hn.hnms.biz.gasext.dws.mapper.DwsAqjcYcbjDFMapper;
import net.hn.hnms.biz.gasext.dws.mapper.DwsRyDdwRyDFMapper;
import net.hn.hnms.biz.gasext.dws.service.DwsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@DS(value = "dws")
@Service
public class DwsServiceImpl implements DwsService {
    @Resource
    private DwsRyDdwRyDFMapper dwsRyDdwRyDFMapper;

    @Resource
    private DwsAqjcYcbjDFMapper dwsAqjcYcbjDFMapper;
    /**
     * 获取Dws模式的人员数据
     * @param date
     * @return
     */
    @Override
    public List<DwsRyDdwRyDFPo> getMineDwsRydwListByDate(List<String> mineCodeList, Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String format = simpleDateFormat.format(date);
        List<DwsRyDdwRyDFPo> list = null;
        LambdaQueryWrapper<DwsRyDdwRyDFPo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DwsRyDdwRyDFPo::getDt, format);
        // 如果 mineCodeList 不为空，则添加 in 条件
        if (mineCodeList != null && !mineCodeList.isEmpty()) {
            wrapper.in(DwsRyDdwRyDFPo::getMkbm, mineCodeList);
        }
        if (date == null) {
            list = dwsRyDdwRyDFMapper.selectList(null);
        } else {

            list = dwsRyDdwRyDFMapper.selectList(wrapper);
        }
        return list;
    }

    /**
     * 获取Dws模式的安全监控测点报警数据
     * @param date
     * @return
     */
    @Override
    public List<DwsAqjcYcbjDFPo> getMineDwsAqjkCdbjListByDate(List<String> mineCodeList, Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        String format = simpleDateFormat.format(date);
        List<DwsAqjcYcbjDFPo> list = null;
        LambdaQueryWrapper<DwsAqjcYcbjDFPo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DwsAqjcYcbjDFPo::getDt, format);
        // 如果 mineCodeList 不为空，则添加 in 条件
        if (mineCodeList != null && !mineCodeList.isEmpty()) {
            wrapper.in(DwsAqjcYcbjDFPo::getMkbm, mineCodeList);
        }

        if (date == null) {
            list = dwsAqjcYcbjDFMapper.selectList(null);
        } else {
            list = dwsAqjcYcbjDFMapper.selectList(wrapper);
        }
        return list;
    }
}
